home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 001-025 / scopedisk7 / rxutil / arcall.rexx < prev    next >
OS/2 REXX Batch file  |  1995-03-18  |  3KB  |  80 lines

  1. /* arcall.rexx -  an ARexx program that will ARC all files within a
  2.                   directory, including subdirectories. It will rename all
  3.                   files to the form 'File1', 'File2', etc. and will
  4.                   generate a standard Amigados script file that will
  5.                   be included in the .ARC file. This script file, when
  6.                   executed, recreates the original file structure, creating
  7.                   any necessary subdirectories and renaming all files back
  8.                   to their original names.
  9.                   Arcall will take an optional argument consisting of the
  10.                   name of the directory you wish to operate on. Otherwise
  11.                   it will ARC the contents of the current directory.
  12.  
  13.    WARNING:       This program does not handle filenames containing spaces.
  14.  
  15.    By Larry Phillips. Compuserve: 76703,4322
  16.    Use this code in whatever way you like.
  17. */
  18.  
  19. parse arg root
  20.  
  21. if words(root) = 0 then root = pragma('d')
  22. if right(root,1) ~= ':' then root = root || '/'
  23. if root = ':' then  root = ''
  24.  
  25. filecount = 1
  26.  
  27. if ~exists(root || 'exec.me') then
  28.   do
  29.    dummy = open(execfile,root || 'Exec.me','write')
  30.    call writeln(execfile,'echo "You may delete the file called EXEC.ME when the prompt comes back."')
  31.    end
  32. else
  33.   do
  34.    dummy = open(execfile,root || 'Execute.me','write')
  35.    call writeln(execfile,'echo "WARNING:"')
  36.    call writeln(execfile,'echo "This archive contains a file called EXEC.ME"') 
  37.    call writeln(execfile,'echo "You will probably need to execute it after this script ends."')
  38.    call writeln(execfile,'echo "You can delete EXECUTE.ME when the prompt comes back."')
  39.   end
  40.  
  41. call writeln(execfile,'')
  42.  
  43. call renamefiles(root)
  44.  
  45. say
  46. call close(execfile)
  47. address command 'arc a' root || 'arcfile' root || '*'
  48. exit 0
  49.  
  50. renamefiles: procedure expose filecount root
  51.   parse arg x
  52.   contents = showdir(x);
  53.   do i = 1 to words(contents)
  54.     temp = x || word(contents,i)
  55.     type = statef(temp)
  56.     select
  57.       when word(type,1) = 'FILE' then do
  58.         address command rename temp root || 'File' || filecount
  59.         call writeln(execfile,'rename File' || filecount x || word(contents,i))
  60.         call writech(stdout,'.')
  61.         filecount = filecount + 1
  62.         end
  63.       when word(type,1) = 'DIR' then do
  64.         call writeln(execfile,'')
  65.         call writeln(execfile,'if NOT EXISTS' temp)
  66.         call writeln(execfile,'  makedir' temp)
  67.         call writeln(execfile,'endif')
  68.         call writeln(execfile,'')
  69.         call renamefiles(temp || '/')
  70.       end
  71.       otherwise do
  72.         if right(translate(temp),7) = 'EXEC.ME' then break
  73.         if right(translate(temp),10) = 'EXECUTE.ME' then break
  74.         else say 'Error: File' temp 'is neither DIR nor FILE.'
  75.       end
  76.     end
  77.   end
  78.   call writeln(execfile,'')
  79. return 0
  80.